package com.xwyzsn.rentcar.controller;
import com.xwyzsn.rentcar.entity.User;
import com.xwyzsn.rentcar.service.UserService;
import com.xwyzsn.rentcar.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

@RestController()
@RequestMapping(value = "/user")
@CrossOrigin(value = "*")
public class UserController {

    @Autowired
    private UserService userService;
    @PostMapping("/get_one")
    public List<User> getOne(@RequestBody Map<String,?> payload){
        System.out.println(payload);
        return userService.getOne(payload);
    }
    @PostMapping("/login")
    public Result login(@RequestBody Map<String,?> payload){
        return userService.login(payload);
    }

    @PostMapping("/getInfo")
    public Result getInfo(@RequestBody Map<String,?> payload){
        return userService.getInfo(payload);
    }


    @PostMapping("/add_one")
    public Result addOne(@RequestBody Map<String,?>payload){
        Boolean res = userService.addOne(payload);
        if(!res){
            return Result.fail("用户名已存在");
        }else{
            return Result.succ(res);
        }
    }

    @PostMapping("/delete_one")
    public Boolean deleteOne(@RequestBody Map<String,?>payload){
        return userService.deleteOne(payload);
    }

    @PostMapping("/update_one")
    public Result updateOne(@RequestBody Map<String,?>payload){
        return Result.succ(userService.updateOne(payload));
    }
    @GetMapping("/hello")
    public  String hello(){
        return "hello";
    }
}
